/*
 * BusinessObject.java
 *
 * Created on October 3, 2007, 11:19 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package petstore.model;

import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 *
 * @author Tom Hayden
 */
@MappedSuperclass
public class BusinessObject implements Serializable {
    
    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    protected Integer id;
    
    public BusinessObject() {
    }
    
    public BusinessObject(Integer id) {
        this.id = id;
    }
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    
    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this TipoEndereco.  The result is 
     * <code>true</code> if and only if the argument is not null and is a TipoEndereco object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        if(! this.getClass().isInstance(object) ) {
        //if (!(object instanceof TipoEndereco)) {
            return false;
        }
        BusinessObject other = (BusinessObject)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return this.getClass().getName()+":\nid=" + this.id;
    }
    
}
